<template>
    <div style="width: 86%;margin: 0 auto;margin-top: 50px;">
        <el-button
            :style='{ "border": "0", "cursor": "pointer", "padding": "0 10px", "margin": "0 5px 0 0", "outline": "none", "color": "#333", "borderRadius": "0px", "background": "#1abc9e30", "width": "auto", "lineHeight": "36px", "fontSize": "14px", "height": "36px" }'
            type="warning" size="mini" @click="backClick" class="el-icon-back">返回</el-button>
        <el-table :data="tableData" style="width: 100%" height="600" :loading="loading">
            <el-table-column prop="date" label="头像">
                <template slot-scope="scope">
                    <el-image :src="`/springbootq81q3hlu/${scope.row.avatarurl}`"
                        style="width: 50px;height: 50px;border-radius: 50%;"></el-image>
                </template>
            </el-table-column>
            <el-table-column prop="nickname" label="姓名" />
            <el-table-column prop="shoujihaoma" label="手机号">
                <template slot-scope="scope">
                    {{maskPhoneNumber(scope.row.shoujihaoma)}}
                </template>
            </el-table-column>
            <el-table-column prop="xingbie" label="性别" />
            <el-table-column prop="addtime" label="关注时间" />
            <el-table-column prop="addtime" label="关注时间">
                <template slot-scope="scope">
                    <el-button @click="handleDelete(scope.row)" type="text" size="small">取消关注</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="paginationBox">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="paginationObj.page" :page-sizes="[10, 20, 30, 40]" :page-size="100"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
export default {
    data() {
        return {
            tableData: [],
            paginationObj: {
                page: 1,
                limit: 10
            },
            total: 0,
            loading: false
        }
    },
    created() {
        this.getListData()
    },
    methods: {
        maskPhoneNumber(phoneNumber) {
            return phoneNumber.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
        },
        handleDelete(row) {
            this.$http.delete('follow/delete', { params: { ids: row.id } }).then(res => {
                this.getListData()
            })
        },
        getListData() {
            this.loading = true
            this.$http.get('follow/page', { params: { ...this.paginationObj } }).then(res => {
                if (res.data.code == 0) {
                    this.tableData = res.data.data.list;
                    this.total = res.data.data.total;
                }
            }).finally(() => {
                this.loading = false
            });
        },
        handleSizeChange(val) {
            this.paginationObj.limit = val;
            this.getListData()
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.paginationObj.page = val;
            this.getListData()
            console.log(`当前页: ${val}`);
        },
        backClick() {
            this.$router.push('/index/center')
        },
    },
}
</script>
<style scoped>
.paginationBox {
    padding: 50px 0;
}
</style>